<template>
<div>
    <div class="box-mid">
        <el-button type="primary" @click="$emit('add', true, {})">创建项目</el-button>
        <el-button @click="handleRemove">批量删除</el-button>
    </div>
    <div class="box-table">
        <el-table :data="tableData.list" tooltip-effect="dark" @selection-change="handleSelected">
            <el-table-column align="center" type="selection" width="55"></el-table-column>
            <el-table-column align="center" prop="name" label="项目名称" width="200">
                <template slot-scope="scope">
                    <el-tooltip class="item" effect="dark" :content="scope.row.name" placement="bottom">
                        <el-button type="text" @click="$router.push('/projects/projectSet/sets')">{{ scope.row.name }}</el-button>
                    </el-tooltip>
                </template>
            </el-table-column>
            <el-table-column align="center" prop="name" label="项目代码" show-overflow-tooltip></el-table-column>
            <el-table-column align="center" prop="name" label="项目管理员" show-overflow-tooltip></el-table-column>
            <el-table-column align="center" label="创建时间" show-overflow-tooltip>
                <template slot-scope="scope">{{ scope.row.date }}</template>
            </el-table-column>
            <el-table-column align="center" label="操作">
                <template slot-scope="scope">
                    <el-button @click="$emit('add', false, scope.row)" type="text">进入机器学习</el-button>
                </template>
            </el-table-column>
        </el-table>
    </div>
    <div class="box-pagenation">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="tableData.currentPage" :page-size="tableData.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="tableData.total">
        </el-pagination>
    </div>
</div>
</template>

<script>
export default {
    name: 'ProjectsTable',
    props: {
        tableData: {
            type: Object,
            required: true
        }
    },
    data () {
        return {
            selected: []
        }
    },
    methods: {
        handleRemove () {
            if (this.selected.length > 0) {
                this.$message.success('删除成功')
                this.$emit('flash')
            } else {
                this.$message.error('请先选择操作对象')
            }
        },
        handleCurrentChange (val) {
            this.tableData.currentPage = val
            this.$emit('flash')
        },
        handleSizeChange (val) {
            this.tableData.pageSize = val
            this.$emit('flash')
        },
        handleSelected (val) {
            this.selected = val
        }
    }
}
</script>

<style lang="less">
.box-table {}
</style>
